<?php $this->load->view('templates/backend/header'); ?>
<?php $this->load->view('templates/backend/lib'); ?>
<h3><?php echo $this->lang->line("refundTicket_list");?></h3>
<style>
.num_cls{
    width:15%;
}
.btn-success,.btn-danger{
    vertical-align: top;
}
.notice{
    color:green;
}
</style>
<div class="well">
    <?php echo form_open();?>
        <div class="tab-content">	
            <div class="tab-pane active" id="main">
                <?php
                //sdt kh
                echo form_label($this->lang->line('phone').' <span class="required">*</span>', 'phone');
                echo form_input(array('name' => 'phone', 'id' => 'phone', 'value' => (isset($refundTicket->phone))?$refundTicket->phone:'','required'=>'required','class'=>'num_cls','readonly' => 'true'));
                echo form_error('phone');
                echo form_input(array('type'=>'hidden','name' => 'customerID', 'id' => 'customerID', 'value' => (isset($refundTicket->customerID))?$refundTicket->customerID:''));
                //hãng hàng không
                echo form_label($this->lang->line('airline').' <span class="required">*</span>', 'airline');
                echo form_input(array('name' => 'airline', 'id' => 'airline', 'value' => (isset($refundTicket->airline))?$refundTicket->airline:'','required'=>'required','maxlength'=>'2'));
                echo form_error('airline');
                //mã đặt chỗ - giá vé
                echo form_label($this->lang->line('booking_place_code').'/Số vé'.' <span class="required">*</span>', 'booking_place_code');
                echo form_input(array('name' => 'booking_place_code', 'id' => 'booking_place_code', 'value' => (isset($refundTicket->booking_place_code))?$refundTicket->booking_place_code:'','required'=>'required','maxlength'=>'13'));
                echo form_error('booking_place_code');
                //Giá net
                echo form_label($this->lang->line('net_fare').' <span class="required">*</span>', 'net_fare');
                echo form_input(array('name' => 'net_fare', 'id' => 'net_fare', 'value' => ($refundTicket->net_fare)?$refundTicket->net_fare:'','required'=>'required'));
                echo form_error('net_fare');
                echo form_input(array('type' => 'hidden','name' => 'net_fare_fake', 'id' => 'net_fare_fake', 'value' => $refundTicket->net_fare));
                //Giá bán
                echo form_label($this->lang->line('sale_fare').' <span class="required">*</span>', 'sale_fare');
                echo form_input(array('name' => 'sale_fare', 'id' => 'sale_fare', 'value' => ($refundTicket->sale_fare)?$refundTicket->sale_fare:'','required'=>'required'));
                echo form_error('sale_fare');
                echo form_input(array('type' => 'hidden','name' => 'sale_fare_fake', 'id' => 'sale_fare_fake', 'value' => $refundTicket->sale_fare));
                //thực trả
                echo form_label($this->lang->line('thuctra').' <span class="required">*</span>', 'thuctra');
                echo form_input(array('name' => 'thuctra', 'id' => 'thuctra', 'value' => ($refundTicket->thuctra)?$refundTicket->thuctra:'','required'=>'required'));
                echo form_error('thuctra');
                echo form_input(array('type' => 'hidden','name' => 'thuctra_fake', 'id' => 'thuctra_fake', 'value' => $refundTicket->thuctra));
                //Phương thức thanh toán
                echo form_label($this->lang->line('payment_method').' <span class="required">*</span>', 'payment_method');
                echo form_dropdown('payment_method', $this->bookhistory_model->_getListPaymentMethod(), ($refundTicket->payment_method)?$refundTicket->payment_method:'','id="payment_method"');
                echo form_error('payment_method');
                echo '<span id="payment_method_form"></span>';
                ?>
            </div>
        </div>
        <div class="top-button">
        <?php
            echo form_button(array('id' => 'accept', 'value' => 'accept', 'name' => 'accept', 'content' => $this->lang->line('save'),'class' => 'btn btn-primary')).' ';
            echo form_button(array('id' => 'cancel','content' => $this->lang->line('close'),'class' => 'btn','onclick'=>'parent.jQuery.fancybox.close()'));
        ?>
        </div>
    <?php form_close();?>
    <span id="simple-msg-submit"></span>
</div>

<?php $this->load->view('templates/backend/footer'); ?>

<script src="<?php echo base_url().'static/templates/backend/js/autoNumeric.js';?>"></script>
<script>
$(document).ready(function() {
    $('#net_fare').autoNumeric('init',{aSign:' VNĐ',mDec:0, pSign:'s' });
    $("#net_fare").blur(function() {
        document.getElementById("net_fare_fake").value = UnFormatNumber($('#net_fare').val());
    });
    $('#sale_fare').autoNumeric('init',{aSign:' VNĐ',mDec:0, pSign:'s' });
    $("#sale_fare").blur(function() {
        document.getElementById("sale_fare_fake").value = UnFormatNumber($('#sale_fare').val());
    });
    $('#thuctra').autoNumeric('init',{aSign:' VNĐ',mDec:0, pSign:'s' });
    $("#thuctra").blur(function() {
        document.getElementById("thuctra_fake").value   = UnFormatNumber($('#thuctra').val());
        $('#payment_method').removeAttr('disabled');
    });
    $("#accept").on('click',function(e) {
            $("#simple-msg-submit").html("<img src='<?php echo base_url().'static/templates/frontend/home/images/';?>loading.gif'/>");
            setTimeout(function (e) {
                $.ajax({
                        url : '/auth/bookhistory/refundTicket',
                        type: "POST",
                        data : { 
                            phone: $("#phone").val(), airline: $("#airline").val(), booking_place_code: $("#booking_place_code").val(),
                            net_fare_fake: $("#net_fare_fake").val(),sale_fare_fake: $("#sale_fare_fake").val(),customerID:$("#customerID").val(),
                            thuctra_fake: $("#thuctra_fake").val(),payment_method: $("#payment_method").val(),bankid:$("#choicebank").val()
                        },
                        cache: false,
                        beforeSend: function(){

                        },
                        success:function(responseData) 
                        {
                            if(responseData == 1){
                                window.top.location.href="/auth/refundTicket/";
                            }
                        },
                        error: function() 
                        {

                        }
                    });
            }, 1000);
            e.preventDefault();	//STOP default action
    });
    $( "#payment_method" ).change(function() {
            if($(this).val() == ""){
                alert("Vui lòng chọn Phương thức thanh toán");return false;
            }
            
            if($("#payment_method").val() != 3){
                $("#payment_method_form").html('');
                return false;
            }
            $('button[type="submit"]').removeAttr('disabled');
            $.ajax(
            {
                    url : '/auth/booking/paymentMethod?id='+$(this).val()+'&cid='+$("#customerID").val(),
                    success:function(data)
                    {
                       $("#payment_method_form").html(data);
                    },
                    error: function() 
                    {
                        alert("Lỗi! Liên hệ Admin!");return false;
                    }
            });
   });
    
    function FormatNumber(x) {
        if (typeof x === "undefined") {
            return '';
        } else {
        return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + ' VNĐ';
        }
    };
    function UnFormatNumber(x) {
        if (typeof x === "undefined") {
            return '';
        } else {
        return x.toString().replace(/,|VNĐ|\s/g, "");
        }
    };
});
</script>
